package com.teen9g.infoplatformserver.controller;

import com.github.pagehelper.PageInfo;
import com.teen9g.PageQueryDTO.FansAndFollowsPageQueryDTO;
import com.teen9g.dto.FansAndFollowsAddDTO;
import com.teen9g.infoplatformserver.service.FollowService;
import com.teen9g.result.Result;
import com.teen9g.vo.FansVO;
import com.teen9g.vo.FollowsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/follow")
public class FollowController {

    @Autowired
    private FollowService followService;

    /**
     * 添加关注信息
     *
     * @param fansAndFollowsAddDTO 关注信息
     * @return 添加结果
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody FansAndFollowsAddDTO fansAndFollowsAddDTO) {
        log.info("添加关注信息：{}", fansAndFollowsAddDTO);
        String result = followService.add(fansAndFollowsAddDTO);
        return Result.success(result);
    }

    /**
     * 取关
     *
     * @param fansId    粉丝id
     * @param followsId 被关注者id
     * @return 删除结果
     */
    @DeleteMapping("/delete/{fansId}/{followsId}")
    public Result<String> delete(@PathVariable Integer fansId, @PathVariable Integer followsId) {
        log.info("取关：粉丝id:{}，被关注者id:{}", fansId, followsId);
        String result = followService.delete(fansId, followsId);
        return Result.success(result);
    }

    /**
     * 分页查询关注信息
     *
     * @param queryDTO 查询条件
     * @return 分页数据
     */
    @GetMapping("/page/follows")
    public Result<PageInfo<FollowsVO>> page(FansAndFollowsPageQueryDTO queryDTO) {
        log.info("分页查询关注信息：{}", queryDTO);
        PageInfo<FollowsVO> result = followService.pageFollows(queryDTO);
        return Result.success(result);
    }

    /**
     * 分页查询粉丝信息
     *
     * @param queryDTO 查询条件
     * @return 分页数据
     */
    @GetMapping("/page/fans")
    public Result<PageInfo<FansVO>> pageFans(FansAndFollowsPageQueryDTO queryDTO) {
        log.info("分页查询粉丝信息：{}", queryDTO);
        PageInfo<FansVO> result = followService.pageFans(queryDTO);
        return Result.success(result);
    }

    /**
     * 查询用户之间的关注状态 用于返回给前端的字符串
     *
     * @param userId1 用户ID1-当前用户
     * @param userId2 用户ID2
     * @return 关注状态
     */
    @GetMapping("/status/{userId1}/{userId2}")
    public Result<String> getStatus(@PathVariable Integer userId1, @PathVariable Integer userId2) {
        log.info("查询用户{}和用户{}的关注状态", userId1, userId2);
        String result = followService.getStatus(userId1, userId2);
        return Result.success(result);
    }
}
